Cadenza : Cadenza Namespace

Either<T1,T2,T3,T4> Generic Class

A union of 4 values.

public abstract class Either<T1, T2, T3, T4> : IEquatable<Either<T1, T2, T3, T4>>

Type Parameters

T1
The first value type.
T2
The second value type.
T3
The third value type.
T4
The fourth value type.

Remarks

An Either is an immutable, strongly typed union of variously typed values with each value lacking an otherwise meaningful name aside from its position, which is not exposed. It stores only one (non-null) value from a set of types (as determined by the type parameter list).

The value held by a Cadenza.Either<T1, T2, T3, T4> instance can be converted into a value by using the Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) method. Fold takes a list of delegates to perform the conversion; the delegate used to perform the conversion is based upon the internal position of the value stored.

Either instances are created through one of the following creation methods:

C# Example
            var a = Either<double, string>.A (Math.PI);   // value stored in 1st position
            int r = a.Fold (
            v => (int) v,                                 // 1st position converter
            v => v.Length);                               // 2nd position converter
            Console.WriteLine (r);                        // prints 3

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Members

See Also: Inherited members from object.

Public Methods

static
A (T1) : Either<T1, T2, T3, T4>
Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T1 value.
static
B (T2) : Either<T1, T2, T3, T4>
Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T2 value.
static
C (T3) : Either<T1, T2, T3, T4>
Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T3 value.
static
D (T4) : Either<T1, T2, T3, T4>
Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T4 value.
abstract
Equals (Either<T1, T2, T3, T4>) : bool
Determines whether the current instance and the specified Cadenza.Either<T1, T2, T3, T4> have the same value.
abstract
Equals (object) : bool
Determines whether the current instance and the specified object have the same value.
abstract
Fold<TResult> (Func<T1, TResult>, Func<T2, TResult>, Func<T3, TResult>, Func<T4, TResult>) : TResult
Converts a Cadenza.Either<T1, T2, T3, T4> into a TResult value.
abstract
GetHashCode () : int
Generates a hash code for the current instance.

Public Operators

static
Conversion to Cadenza.Either<T1,T2,T3,T4> (Implicit) Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T1 value.
static
Conversion to Cadenza.Either<T1,T2,T3,T4> (Implicit) Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T2 value.
static
Conversion to Cadenza.Either<T1,T2,T3,T4> (Implicit) Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T3 value.
static
Conversion to Cadenza.Either<T1,T2,T3,T4> (Implicit) Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T4 value.

Extension Methods

static
Just<T> (this T) : Maybe<T>
Create a new Cadenza.Maybe<T> instance initialized to a specified value. The returned value will not be Maybe<T>.Nothing.
static
Match<TSource,TResult> (this TSource, params Func<TSource, Maybe<TResult>>[]) : TResult
Converts the TSource instance self into a TResult.
static
ToMaybe<T> (this T) : Maybe<T>
Create a new Cadenza.Maybe<T> instance initialized to a specified value. The returned value may be Maybe<T>.Nothing.
static
TraverseBreadthFirst<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<TResult>
Traverse a tree in a breadth-first fashion, converting each encountered node.
static
TraverseBreadthFirstWithParent<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<KeyValuePair<TSource, TResult>>
Traverse a tree in a breadth-first fashion, converting each encountered node.
static
TraverseDepthFirst<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<TResult>
Traverse a tree in a depth-first fashion, converting each encountered node.
static
TraverseDepthFirstWithParent<TSource,TResult> (this TSource, Func<TSource, TResult>, Func<TSource, IEnumerable<TSource>>) : IEnumerable<KeyValuePair<TSource, TResult>>
Traverse a tree in a depth-first fashion, converting each encountered node.
static
With<TSource,TResult> (this TSource, Func<TSource, TResult>) : TResult
Supports chaining otherwise temporary values.

Member Details

A Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T1 value.

public static Either<T1, T2, T3, T4> A (T1 value)

Parameters

value
A T1 containing the value to provide to the first Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) delegate.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a holds a T1 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

When Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3, T4> instance will invoke the first delegate for conversions.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

B Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T2 value.

public static Either<T1, T2, T3, T4> B (T2 value)

Parameters

value
A T2 containing the value to provide to the second Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) delegate.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a holds a T2 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

When Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3, T4> instance will invoke the second delegate for conversions.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

C Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T3 value.

public static Either<T1, T2, T3, T4> C (T3 value)

Parameters

value
A T3 containing the value to provide to the third Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) delegate.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a holds a T3 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

When Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3, T4> instance will invoke the third delegate for conversions.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

D Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T4 value.

public static Either<T1, T2, T3, T4> D (T4 value)

Parameters

value
A T4 containing the value to provide to the fourth Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) delegate.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a holds a T4 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

When Either<T1, T2, T3, T4>.Fold``1(Func<`0, ``0>, Func<`1, ``0>, Func<`2, ``0>, Func<`3, ``0>) is invoked, the returned Cadenza.Either<T1, T2, T3, T4> instance will invoke the fourth delegate for conversions.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Equals Method

Determines whether the current instance and the specified Cadenza.Either<T1, T2, T3, T4> have the same value.

public abstract bool Equals (Either<T1, T2, T3, T4> obj)

Parameters

obj
A Cadenza.Either<T1, T2, T3, T4>to compare this instance against.

Returns

true if each member of obj and the current instance have the same value (according to object.Equals(object)); otherwise false is returned.

Remarks

This method checks for value equality (object.Equals(object)), as defined by each value type.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Equals Method

Determines whether the current instance and the specified object have the same value.

public abstract bool Equals (object obj)

Parameters

obj
A object to compare this instance against.

Returns

true if obj is a Cadenza.Either<T1, T2, T3, T4> and each member of obj and the current instance have the same value (according to object.Equals(object)); otherwise false is returned.

Remarks

This method checks for value equality (object.Equals(object)), as defined by each value type.

Note: This method overrides object.Equals(object).

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Fold<TResult> Generic Method

Converts a Cadenza.Either<T1, T2, T3, T4> into a TResult value.

public abstract TResult Fold<TResult> (Func<T1, TResult> a, Func<T2, TResult> b, Func<T3, TResult> c, Func<T4, TResult> d)

Type Parameters

TResult
The type to convert the Cadenza.Either<T1, T2, T3, T4> to.

Parameters

a
A Func<T1, TResult> used if the Cadenza.Either<T1, T2, T3, T4> stores a T1 value into a TResult value.
b
A Func<T2, TResult> used if the Cadenza.Either<T1, T2, T3, T4> stores a T2 value into a TResult value.
c
A Func<T3, TResult> used if the Cadenza.Either<T1, T2, T3, T4> stores a T3 value into a TResult value.
d
A Func<T4, TResult> used if the Cadenza.Either<T1, T2, T3, T4> stores a T4 value into a TResult value.

Returns

A TResult as generated by one of the conversion delegate parameters.

Exceptions

Type Reason
ArgumentNullException

a is null.

-or-

b is null.

-or-

c is null.

-or-

d is null.

Remarks

Converts a Cadenza.Either<T1, T2, T3, T4> into a TResult by invoking one of the provided delegate parameters.

The parameter which is invoked is predicated upon the internal position of the value held. For example, if the internal value is in the first position (i.e. Either<T1, T2, T3, T4>.A(`0) was used to create the Cadenza.Either<T1, T2, T3, T4> instance), then a (the first delegate parameter) will be invoked to convert the T1 into a TResult.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

GetHashCode Method

Generates a hash code for the current instance.

public abstract int GetHashCode ()

Returns

A int containing the hash code for this instance.

Remarks

Note: This method overrides object.GetHashCode.

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Conversion Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T1 value.

public static implicit operator Either<T1, T2, T3, T4> (T1 value)

See Also

Either<T1, T2, T3, T4>.A(`0)

Parameters

value
A T1 containing the value to store.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a T1 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

This conversion operator is provided to make Cadenza.Either<T1, T2, T3, T4> instance creation easier:

C# Example
        Either<int, double> value = 42.0;  // value stored in 2nd position

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Conversion Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T2 value.

public static implicit operator Either<T1, T2, T3, T4> (T2 value)

See Also

Either<T1, T2, T3, T4>.B(`1)

Parameters

value
A T2 containing the value to store.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a T2 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

This conversion operator is provided to make Cadenza.Either<T1, T2, T3, T4> instance creation easier:

C# Example
        Either<int, double> value = 42.0;  // value stored in 2nd position

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Conversion Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T3 value.

public static implicit operator Either<T1, T2, T3, T4> (T3 value)

See Also

Either<T1, T2, T3, T4>.C(`2)

Parameters

value
A T3 containing the value to store.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a T3 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

This conversion operator is provided to make Cadenza.Either<T1, T2, T3, T4> instance creation easier:

C# Example
        Either<int, double> value = 42.0;  // value stored in 2nd position

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0

Conversion Method

Creates a Cadenza.Either<T1, T2, T3, T4> instance which holds a T4 value.

public static implicit operator Either<T1, T2, T3, T4> (T4 value)

See Also

Either<T1, T2, T3, T4>.D(`3)

Parameters

value
A T4 containing the value to store.

Returns

A Cadenza.Either<T1, T2, T3, T4> instance which holds a T4 value.

Exceptions

Type Reason
ArgumentNullException if value is null.

Remarks

This conversion operator is provided to make Cadenza.Either<T1, T2, T3, T4> instance creation easier:

C# Example
        Either<int, double> value = 42.0;  // value stored in 2nd position

Requirements

Namespace: Cadenza
Assembly: Cadenza (in Cadenza.dll)
Assembly Versions: 0.1.0.0